package net.digitalartwork.geoslideshow {
	import flash.display.*;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.*;
	import flash.events.*;
	import flash.text.*;
	
	import gs.TweenFilterLite;
	import gs.OverwriteManager;
	import gs.easing.*;
	
	
	public class DASortByBtn extends MovieClip{
		
		//--------------------------------------------------------------------------
		// ASSETS
		//--------------------------------------------------------------------------
		public var bg:MovieClip;
		public var btn_text_mc:MovieClip;
		//--------------------------------------------------------------------------
		// DISPATCH
		//--------------------------------------------------------------------------
		public var MOUSECLICK:String = "mousedown";
		public var TOGGLE1:String = "toggle1";
		public var TOGGLE2:String = "toggle2";
		public var SIZECHANGE:String = "sizechange";
		//--------------------------------------------------------------------------
		// VARIABLES
		//--------------------------------------------------------------------------
		private var toggleColor1:Number = 0x999999;
		private var toggleColor2:Number = 0xFFFFFF;
		public var _sort_name:String;
		//--------------------------------------------------------------------------
		
		public function DASortByBtn() {
			trace("BasicButton Init");
			//OverwriteManager.init();
			//--------------------------------------------------------------------------
			// Button Text
			//--------------------------------------------------------------------------
			btn_text_mc.mouseEnabled = false;
			btn_text_mc.mouseChildren = false;
			btn_text_mc.btn_text.autoSize = "left";

			btn_text_mc.alpha = 1;
			btn_text_mc.btn_text.textColor = toggleColor1;
			//TweenFilterLite.to(btn_text_mc, .2, {alpha:.1});
			//--------------------------------------------------------------------------
			// Button BG
			//--------------------------------------------------------------------------
			bg.width = btn_text_mc.btn_text.textWidth + 8;
			bg.alpha = 0;
			bg.buttonMode = true; 
			bg.useHandCursor = true;
			bg.addEventListener(MouseEvent.ROLL_OVER, onRollOverHandler); 
			bg.addEventListener(MouseEvent.ROLL_OUT, onRollOutHandler); 
			bg.addEventListener(MouseEvent.CLICK, onClickHandler); 
			//bg.addEventListener(MouseEvent.MOUSE_DOWN, onPressHandler); 
			//bg.addEventListener(MouseEvent.MOUSE_UP, onReleaseHandler);
		}
		
		private function onRollOverHandler(e:MouseEvent):void {
			bg.alpha = 1;
			//btn_text_mc.alpha = 1;
			//bg.btn_bg_bounds.alpha = .5;
			
		}
		private function onRollOutHandler(e:MouseEvent):void {
			bg.alpha = 0;
			//btn_text_mc.alpha = .8;
			//bg.btn_bg_bounds.alpha = .25;
			
		}
		private function onClickHandler(e:MouseEvent):void {
			dispatchEvent(new Event(MOUSECLICK));
			toggleState(false);
			/*
			if (bg.btn_toggle2.visible == true) {
				bg.btn_toggle2.visible  = false;
				bg.btn_toggle1.visible = true;
				toggleState(false);
				trace("TOGGLE1");
				dispatchEvent(new Event(TOGGLE1));
			} else {
				bg.btn_toggle2.visible  = true;
				bg.btn_toggle1.visible = false;
				toggleState(true);
				dispatchEvent(new Event(TOGGLE2));
			}
			*/
			
		}
		
		public function toggleOff():void {
			toggleState(true);
		}
		public function toggleOn():void {
			toggleState(false);
		}
		
		private function toggleState(s:Boolean = false):void {
			
			if (s) {
				btn_text_mc.btn_text.textColor = toggleColor1;
			} else {
				btn_text_mc.btn_text.textColor = toggleColor2;
			}
			
			
		}
		
		public function setButtonText(t1:String):void {
			
			btn_text_mc.btn_text.text = t1;
			bg.width = btn_text_mc.btn_text.textWidth + 8;
			
		}
		
	}
	
}